Skip to content

feat: add env init command that copies from template placeholders#516

Merged
zimeg merged 7 commits into
mainfrom
zimeg-feat-env-init
May 14, 2026
Merged

feat: add env init command that copies from template placeholders#516
zimeg merged 7 commits into
mainfrom
zimeg-feat-env-init

Conversation

@zimeg
Copy link
Copy Markdown
Member

@zimeg zimeg commented Apr 30, 2026

Changelog

A new env init command copies a template placeholder ".env.sample" or ".env.example" file to the ".env" file of a project.

Summary

This PR adds the env init command that copies from template placeholders 🌲

Preview

Included are expected cases and common edges to encounter! 🔬 ✨

⚡ Bolt Frameworks

  1. An existing placeholder file is used for the new ".env" file
  2. An existing ".env" file is not overwritten
  3. A missing placeholder file notes to use "env set" command
bolt

🥀 ROSI Features

  1. Deployed apps recommend the "env set" command
  2. Local development requires selection and saves to project file
rosi

Testing

Checkout the changes of this branch and experiment with either a Bolt or Deno app:

$ slack create asdf
$ cd asdf
$ slack install     # Required for Deno - Optional for Bolt
$ cat .env.sample   # Inspect values upcoming
$ slack env init
$ cat .env
$ slack env init    # Reattempt the initilization

Notes

Some follow up remains proposed to improve this but is left out of scope for this PR 🏁

  • Prompting for values included in placeholders might be a meaningful improvement to avoid unexpected values. We might find the following format interesting toward this but without much exploration right now:
# COMMENTED_VARIABLE=       # Not prompted
UNCOMMENTED_VARIABLE=       # Prompted
SET_VARIABLE=debug_example  # Not prompted
  • Including this command as part of project init ought make setup a breeze it's been said 😉

Requirements

@zimeg zimeg added this to the Next Release milestone Apr 30, 2026
@zimeg zimeg self-assigned this Apr 30, 2026
@zimeg zimeg requested a review from a team as a code owner April 30, 2026 04:32
@zimeg zimeg added enhancement M-T: A feature request for new functionality changelog Use on updates to be included in the release notes semver:minor Use on pull requests to describe the release version increment labels Apr 30, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

❌ Patch coverage is 89.71963% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.64%. Comparing base (cca9a20) to head (1d39cc6).

Files with missing lines Patch % Lines
internal/slackdotenv/slackdotenv.go 68.18% 5 Missing and 2 partials ⚠️
cmd/env/init.go 95.06% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #516      +/-   ##
==========================================
+ Coverage   71.54%   71.64%   +0.09%     
==========================================
  Files         224      225       +1     
  Lines       18959    19066     +107     
==========================================
+ Hits        13565    13659      +94     
- Misses       4193     4201       +8     
- Partials     1201     1206       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Member

@mwbrooks mwbrooks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙇🏻 Thanks a bunch for opening this PR! 🎉 I'm excited to see this one landing.

🧠 Could we swap "template placeholders" for "template file" or ".env template file"? "Placeholder" tends to imply a variable or token that gets substituted, which is a bit ambiguous here. Since we're copying the file verbatim, ".env template file" is more precise and the common convention in the wild from a little Claude research.

Comment thread cmd/env/env.go Outdated
@zimeg zimeg requested a review from mwbrooks May 13, 2026 10:06
@zimeg
Copy link
Copy Markdown
Member Author

zimeg commented May 13, 2026

@mwbrooks Apologies for the pause after review 🎁 ✨

The polish to how these concepts landed above and I think it puts this in a better place for ongoing iteration! Let's not think about that right now though. I requested another review for sureness of how this appears 🔮

Copy link
Copy Markdown
Member

@mwbrooks mwbrooks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Thanks for the refactors @zimeg! This PR looks great and works like a charm! 👌🏻

🧪 Manual tests are looking good and unit tests have good test coverage.

📝 A few follow-ups that come to mind:

  1. suggestion: We should include env init as part of project init so that the new projects come with a .env provisioned out-of-the-box.
  2. question: When no .env exists and we run env set, the CLI creates .env. Should it create a blank .env or use .env.example/sample when it exists? My first impression is that we'd remain consistent if we tempalted from the .env.example/sample.

// Init copies an .env template file (.env.sample or .env.example) to .env. It
// returns an error if .env already exists, or if no template file is found.
func Init(fs afero.Fs) (string, error) {
sampleFiles := []string{".env.sample", ".env.example"}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: I had Claude do some research on github.com and these are the top 2 placeholder names for .env files and make up the largest percentage. So, I think this is a great start!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mwbrooks Thanks for investigating too! IIRC our samples prefer .env.sample most and I'm willing to extend this as requested 🫡

ErrDenoNotFound = "deno_not_found"
ErrDeployedAppNotSupported = "deployed_app_not_supported"
ErrDocumentationGenerationFailed = "documentation_generation_failed"
ErrDotEnvFileAlreadyExists = "dotenv_file_already_exists"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: error code prefixes for clean organization! 🎉

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mwbrooks The prefix matches the package too! I hope we can continue this pattern as errors are wrapped across boundaries 🎁 ✨

@zimeg
Copy link
Copy Markdown
Member Author

zimeg commented May 14, 2026

@mwbrooks Super duper appreciate this being brought to the finish line! Thanks for sharing suggestions and feedback ahead 🏁

I like both ideas if this init command continues to avoid prompting:

  • During project init: We save the cp .env.sample .env command without setting values. IIRC projects might expect some values but emptiness should continue to error?
  • Before env set: Similar great ideas. It makes "init" an invisible command and I like that because it can't be run after "set" so missing values would be a bummer.

Let's soon merge this for upcoming release I think! 🚢 💨

@zimeg zimeg merged commit 5aa11dd into main May 14, 2026
10 checks passed
@zimeg zimeg deleted the zimeg-feat-env-init branch May 14, 2026 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog Use on updates to be included in the release notes enhancement M-T: A feature request for new functionality semver:minor Use on pull requests to describe the release version increment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants